import pypandoc

def md_to_docx(input_md, output_docx):
    """将 Markdown 转换为 Word 文档"""
    try:
        # 核心转换函数，附加目录生成参数
        output = pypandoc.convert_file(
            input_md, 
            'docx', 
            outputfile=output_docx,
            extra_args=['--toc']  # 生成目录
        )
        print(f"转换成功：{output_docx}")
    except Exception as e:
        print(f"转换失败：{e}")

# 调用示例
md_to_docx("report.md", "report.docx")  # 输入输出文件路径

if __name__ == "__main__":
    markdown_file_path = r"/Users/elonmar/Downloads/111.md"
    word_file_path = r"/Users/elonmar/Downloads/test.docx"

    md_to_docx(markdown_file_path, word_file_path)
